package com.distribute.core.monitor;

/**
 *  监控统计工具：缓存对象内存统计
 *
 * @author chennengcheng
 * @date 2021-09-22 15:49
 * @remark
 */
public class MemoryStatics {

    /**
     * 内存统计信息
     */
    public static JvmMemoryMessage staticsMemory() {
        // 虚拟机级内存情况查询
        int byteToMb = 1024 * 1024;
        Runtime rt = Runtime.getRuntime();
        long vmTotal = rt.totalMemory() / byteToMb;
        long vmFree = rt.freeMemory() / byteToMb;
        long vmUse = vmTotal - vmFree;
        return new JvmMemoryMessage(vmUse + " MB", vmFree + " MB", vmTotal + " MB");
    }
}
